import axios from 'axios'
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1'
axios.interceptors.request.use(
	function (config) {
		config.headers.Authorization = sessionStorage.getItem('token')
		return config
	},
	function (error) {
		return Promise.reject(error)
	}
)
export default {
	namespaced: true,
	actions: {
		getData(context, value) {
			if (!value) {
				value = {
					type: context.state.type,
					pagenum: context.state.pagenums,
					pagesize: context.state.pagesizes,
				}
			}

			axios
				.get('/categories', {
					params: {
						type: value.type,
						pagenum: value.pagenum,
						pagesize: value.pagesize,

					},
				})
				.then(response => {
					let { data, meta } = response.data
					if (meta.status != 200) {
						console.log('获取列表失败，请求路径/categories')

					}
					context.commit('GETDATA', { value, data })

				})
				.catch(error => {
					console.log(error.message)
				})
		},
	},
	mutations: {

		GETDATA(state, value) {
			state.getData = value.data.result
			state.pagenum = value.data.pagenum
			state.pagesize = value.data.pagesize
			state.total = value.data.total
			state.type = value.value.type
			state.pagenums = value.value.pagenum
			state.pagesizes = value.value.pagesize
		},
	},
	state: {
		getData: '',
		pagenum: '',
		pagesize: '',
		total: 0,
		type: '',
	},

	getters: {},
}
